---
title: "No One Mourns the Wicked: Partisan Hostility Persisting through Tragedy"
author: "Anonymized"
date: "07/28/23"
output:
  html_document:
    toc: true
    code_folding: hide
  latex_engine: xelatex
  number_sections: yes
mainfont: Helvetica
---

# Setting up the Data {.tabset}

## Loading packages and data

```{r setup, message = FALSE, warning = FALSE, results ='hide'}

##### Packages #####

library(descr)
library(ggplot2)
library(dplyr)
library(foreign)
library(plyr)
library(ggpubr)
library(ggeffects)
library(tidyverse)
library(haven)
library(modelsummary)
options("modelsummary_format_numeric_latex" = "mathmode")


# setwd("[pathway to data here]")
# knitr::opts_knit$set(root.dir = '[pathway to data here]')

```

# Load data

```{r Load data}

load('df_rep.Rda'); load('df2_rep.Rda')

```

## Survey Stats

```{r}

colMeans(df, na.rm = T)
colMeans(df2, na.rm = T)

```

# Analysis

## Covid Study

```{r Covid Study}

df1_1 <- group.CI(study1_dv_1 ~ tr1,
                   data = df,
                   ci = 0.90)
df1_1_dem <- group.CI(study1_dv_1 ~ tr1,
                   data = subset(df, gop == 0),
                   ci = 0.90)
df1_1_gop <- group.CI(study1_dv_1 ~ tr1,
                   data = subset(df, gop == 1),
                   ci = 0.90)

df1_2 <- group.CI(study1_dv_2 ~ tr1,
                   data = df,
                   ci = 0.90)
df1_2_dem <- group.CI(study1_dv_2 ~ tr1,
                   data = subset(df, gop == 0),
                   ci = 0.90)
df1_2_gop <- group.CI(study1_dv_2 ~ tr1,
                   data = subset(df, gop == 1),
                   ci = 0.90)

df1_3 <- group.CI(study1_dv_3 ~ tr1,
                   data = df,
                   ci = 0.90)
df1_3_dem <- group.CI(study1_dv_3 ~ tr1,
                   data = subset(df, gop == 0),
                   ci = 0.90)
df1_3_gop <- group.CI(study1_dv_3 ~ tr1,
                   data = subset(df, gop == 1),
                   ci = 0.90)

df1_sym <- group.CI(study1_dv2_1 ~ tr1,
                   data = df,
                   ci = 0.90)
df1_sym_dem <- group.CI(study1_dv2_1 ~ tr1,
                   data = subset(df, gop == 0),
                   ci = 0.90)
df1_sym_gop <- group.CI(study1_dv2_1 ~ tr1,
                   data = subset(df, gop == 1),
                   ci = 0.90)

names(df1_1) <- c('group', 'hi', 'mean', 'lo')
names(df1_1_dem) <- c('group', 'hi', 'mean', 'lo')
names(df1_1_gop) <- c('group', 'hi', 'mean', 'lo')

names(df1_2) <- c('group', 'hi', 'mean', 'lo')
names(df1_2_dem) <- c('group', 'hi', 'mean', 'lo')
names(df1_2_gop) <- c('group', 'hi', 'mean', 'lo')

names(df1_3) <- c('group', 'hi', 'mean', 'lo')
names(df1_3_dem) <- c('group', 'hi', 'mean', 'lo')
names(df1_3_gop) <- c('group', 'hi', 'mean', 'lo')

names(df1_sym) <- c('group', 'hi', 'mean', 'lo')
names(df1_sym_dem) <- c('group', 'hi', 'mean', 'lo')
names(df1_sym_gop) <- c('group', 'hi', 'mean', 'lo')

df1_1$dv <- rep('Victim', 6)
df1_1_dem$dv <- rep('Victim', 6)
df1_1_gop$dv <- rep('Victim', 6)

df1_2$dv <- rep('Govt', 6)
df1_2_dem$dv <- rep('Govt', 6)
df1_2_gop$dv <- rep('Govt', 6)

df1_3$dv <- rep('Activists', 6)
df1_3_dem$dv <- rep('Activists', 6)
df1_3_gop$dv <- rep('Activists', 6)

df1_sym$dv <- rep('Sympathy', 6)
df1_sym_dem$dv <- rep('Sympathy', 6)
df1_sym_gop$dv <- rep('Sympathy', 6)

dat1 <- bind_rows(df1_1,df1_2, df1_3, df1_sym)
dat1_dem <- bind_rows(df1_1_dem, df1_2_dem, df1_3_dem, df1_sym_dem)
dat1_gop <- bind_rows(df1_1_gop, df1_2_gop, df1_3_gop, df1_sym_gop)

```

```{r echo=TRUE}

## Plotting

cbPalette <- c("#CC79A7", "#009E73", "#F0E442", "#0072B2", "#D55E00")

plot1.1 <- ggplot(data = dat1, aes(x = group, y = mean, fill = dv)) +
  theme_bw() + scale_fill_manual(values = cbPalette) +
  geom_bar(stat="identity", position=position_dodge()) +
  geom_errorbar(aes(ymin = lo, ymax = hi),
                size = 0.5, width = 0.1,
                position = position_dodge(0.9)) + 
  scale_x_discrete(name = '\nTreatment Condition', 
                   labels = c('Control', 'Anti-Vax', 'Democrat', 'Republican', 'Anti-Vax Dem', 'Anti-Vax Rep')) +
  coord_cartesian(ylim=c(20, 85)) +
  ylab('Average Blame/Sympathy') +
  labs(title = "Effect of Party and Anti-Vax on Blame Attribution") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position="bottom") +
  theme(text=element_text(family="serif")) +
  guides(fill=guide_legend(title="Blame/Sympathy"))
plot1.1

plot1.dem <- ggplot(data = dat1_dem, aes(x = group, y = mean, fill = dv)) +
  theme_bw() + scale_fill_manual(values = cbPalette) +
  geom_bar(stat="identity", position=position_dodge()) +
  geom_errorbar(aes(ymin = lo, ymax = hi),
                size = 0.5, width = 0.1,
                position = position_dodge(0.9)) + 
  scale_x_discrete(name = '\nTreatment Condition', 
                   labels = c('Control', 'Anti-Vax', 'Democrat', 'Republican', 'Anti-Vax Dem', 'Anti-Vax Rep')) +
  coord_cartesian(ylim=c(20, 85)) +
  ylab('Average Blame/Sympathy') +
  labs(title = "Effect of Party and Anti-Vax on Blame Attribution, Democrats only") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position="bottom") +
  theme(text=element_text(family="serif")) +
  guides(fill=guide_legend(title="Blame/Sympathy"))
plot1.dem

plot1.gop <- ggplot(data = dat1_gop, aes(x = group, y = mean, fill = dv)) +
  theme_bw() + scale_fill_manual(values = cbPalette) +
  geom_bar(stat="identity", position=position_dodge()) +
  geom_errorbar(aes(ymin = lo, ymax = hi),
                size = 0.5, width = 0.1,
                position = position_dodge(0.9)) + 
  scale_x_discrete(name = '\nTreatment Condition', 
                   labels = c('Control', 'Anti-Vax', 'Democrat', 'Republican', 'Anti-Vax Dem', 'Anti-Vax Rep')) +
  coord_cartesian(ylim=c(20, 85)) +
  ylab('Average Blame/Sympathy') +
  labs(title = "Effect of Party and Anti-Vax on Blame Attribution, Republicans only") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position="bottom") +
  theme(text=element_text(family="serif")) +
  guides(fill=guide_legend(title="Blame/Sympathy"))
plot1.gop

```

# Modeling Effects

```{r Modeling Effects}

df$gop <- ifelse(df$pid > 4, 1,
                 ifelse(df$pid < 4, 0, NA))
df2$gop <- ifelse(df2$pid > 4, 1,
                 ifelse(df2$pid < 4, 0, NA))

# blaming victim

m1_1 <- lm(study1_dv_1 ~ factor(tr1), data = df) # 
summary(m1_1)

m1_dem_1 <- lm(study1_dv_1 ~ factor(tr1), data = subset(df, gop == 0)) # 
summary(m1_dem_1)

m1_gop_1 <- lm(study1_dv_1 ~ factor(tr1), data = subset(df, gop == 1)) # 
summary(m1_gop_1)

m2_1 <- lm(study1_dv_1 ~ factor(trgrp), data = df2, weights = teamweight) # 
summary(m2_1)

m2_dem_1 <- lm(study1_dv_1 ~ factor(trgrp), data = subset(df2, gop == 0), weights = teamweight) # 
summary(m2_dem_1)

m2_gop_1 <- lm(study1_dv_1 ~ factor(trgrp), data = subset(df2, gop == 1), weights = teamweight) # 
summary(m2_gop_1)

modelsummary(models = list('Full Sample'  = m1_1,
                           'Democrats' = m1_dem_1,
                           'Republicans' = m1_gop_1),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

modelsummary(models = list('Full Sample'  = m2_1,
                           'Democrats' = m2_dem_1,
                           'Republicans' = m2_gop_1),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

# blaming govt

m1_2 <- lm(study1_dv_2 ~ factor(tr1), data = df) # 
summary(m1_2)

m1_dem_2 <- lm(study1_dv_2 ~ factor(tr1), data = subset(df, gop == 0)) # 
summary(m1_dem_2)

m1_gop_2 <- lm(study1_dv_2 ~ factor(tr1), data = subset(df, gop == 1)) # 
summary(m1_gop_2)

m2_2 <- lm(study1_dv_2 ~ factor(trgrp), data = df2) # 
summary(m2_2)

m2_dem_2 <- lm(study1_dv_2 ~ factor(trgrp), data = subset(df2, gop == 0)) # 
summary(m2_dem_2)

m2_gop_2 <- lm(study1_dv_2 ~ factor(trgrp), data = subset(df2, gop == 1)) # 
summary(m2_gop_2)

# blaming activists

m1_3 <- lm(study1_dv_3 ~ factor(tr1), data = df) # 
summary(m1_3)

m1_dem_3 <- lm(study1_dv_3 ~ factor(tr1), data = subset(df, gop == 0)) # 
summary(m1_dem_3)

m1_gop_3 <- lm(study1_dv_3 ~ factor(tr1), data = subset(df, gop == 1)) # 
summary(m1_gop_3)

m2_3 <- lm(study1_dv_3 ~ factor(trgrp), data = df2) # 
summary(m2_3)

m2_dem_3 <- lm(study1_dv_3 ~ factor(trgrp), data = subset(df2, gop == 0)) # 
summary(m2_dem_3)

m2_gop_3 <- lm(study1_dv_3 ~ factor(trgrp), data = subset(df2, gop == 1)) # 
summary(m2_gop_3)

# sympathy

m1_4 <- lm(study1_dv2_1 ~ factor(tr1), data = df) # 
summary(m1_4)

m1_dem_4 <- lm(study1_dv2_1 ~ factor(tr1), data = subset(df, gop == 0)) # 
summary(m1_dem_4)

m1_gop_4 <- lm(study1_dv2_1 ~ factor(tr1), data = subset(df, gop == 1)) # 
summary(m1_gop_4)

m2_4 <- lm(study1_dv2_1 ~ factor(trgrp), data = df2, weights = teamweight) # 
summary(m2_4)

m2_dem_4 <- lm(study1_dv2_1 ~ factor(trgrp), data = subset(df2, gop == 0), weights = teamweight) # 
summary(m2_dem_4)

m2_gop_4 <- lm(study1_dv2_1 ~ factor(trgrp), data = subset(df2, gop == 1), weights = teamweight) # 
summary(m2_gop_4)

modelsummary(models = list('Full Sample'  = m1_4,
                           'Democrats' = m1_dem_4,
                           'Republicans' = m1_gop_4),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

modelsummary(models = list('Full Sample'  = m2_4,
                           'Democrats' = m2_dem_4,
                           'Republicans' = m2_gop_4),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)


# Testing Group Empathy Theory

## Blame

em_death1.1 <- lm(study1_dv_1 ~ factor(tr1), data = subset(df, coviddeath == 1))
summary(em_death1.1)

em_nodeath1.1 <- lm(study1_dv_1 ~ factor(tr1), data = subset(df, coviddeath == 2))
summary(em_nodeath1.1)

em_death2.1 <- lm(study1_dv_1 ~ factor(trgrp), data = subset(df2, coviddeath == 1), weights = teamweight)
summary(em_death2.1)

em_nodeath2.1 <- lm(study1_dv_1 ~ factor(trgrp), data = subset(df2, coviddeath == 2), weights = teamweight)
summary(em_nodeath2.1)

modelsummary(models = list('COVID Death'  = em_death1.1,
                           'No COVID Death' = em_nodeath1.1,
                           'COVID Death'  = em_death2.1,
                           'No COVID Death' = em_nodeath2.1),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

## Sympathy

em_death1.2 <- lm(study1_dv2_1 ~ factor(tr1), data = subset(df, coviddeath == 1))
summary(em_death1.2)

em_nodeath1.2 <- lm(study1_dv2_1 ~ factor(tr1), data = subset(df, coviddeath == 2))
summary(em_nodeath1.2)

em_death2.2 <- lm(study1_dv2_1 ~ factor(trgrp), data = subset(df2, coviddeath == 1))
summary(em_death2.2)

em_nodeath2.2 <- lm(study1_dv2_1 ~ factor(trgrp), data = subset(df2, coviddeath == 2))
summary(em_nodeath2.2)

modelsummary(models = list('COVID Death'  = em_death1.2,
                           'No COVID Death' = em_nodeath1.2,
                           'COVID Death'  = em_death2.2,
                           'No COVID Death' = em_nodeath2.2),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

## Testing by Vax Status

df$vaxstatus2 <- ifelse((df$vaxstatus == 1 | df$vaxstatus == 2), 1,
                 ifelse(df$vaxstatus == 3, 0, 2))

vac1.1_vax <- lm(study1_dv_1 ~ factor(tr1), data = subset(df, vaxstatus2 == 1))
summary(vac1.1_vax)

vac1.1_novax <- lm(study1_dv_1 ~ factor(tr1), data = subset(df, vaxstatus2 == 0))
summary(vac1.1_novax)

vac1.2_vax <- lm(study1_dv2_1 ~ factor(tr1), data = subset(df, vaxstatus2 == 1))
summary(vac1.2_vax)

vac1.2_novax <- lm(study1_dv2_1 ~ factor(tr1), data = subset(df, vaxstatus2 == 0))
summary(vac1.2_novax)

modelsummary(models = list('Vaccinated'  = vac1.1_vax,
                           'Not Vaccinated' = vac1.1_novax,
                           'Vaccinated'  = vac1.2_vax,
                           'Not Vaccinated' = vac1.2_novax),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

```

## Figures

```{r Figures}

# blaming victim

coef1 <- c(m1_dem_1$coefficients[2:6], m1_gop_1$coefficients[2:6],
           m2_dem_1$coefficients[2:6], m2_gop_1$coefficients[2:6])
se1 <- sqrt(diag(vcov(m1_dem_1))); se2 <- sqrt(diag(vcov(m1_gop_1))); se3 <- sqrt(diag(vcov(m2_dem_1))); se4 <- sqrt(diag(vcov(m2_gop_1)))

hi1 <- c(coef1[1]+(1.96*se1[2]), coef1[2]+(1.96*se1[3]),
            coef1[3]+(1.96*se1[4]), coef1[4]+(1.96*se1[5]),
            coef1[5]+(1.96*se1[6]),
         coef1[6]+(1.96*se2[2]), coef1[7]+(1.96*se2[3]),
            coef1[8]+(1.96*se2[4]), coef1[9]+(1.96*se2[5]),
            coef1[10]+(1.96*se2[6]),
         coef1[11]+(1.96*se3[2]), coef1[12]+(1.96*se3[3]),
            coef1[13]+(1.96*se3[4]), coef1[14]+(1.96*se3[5]),
            coef1[15]+(1.96*se3[6]),
         coef1[16]+(1.96*se4[2]), coef1[17]+(1.96*se4[3]),
            coef1[18]+(1.96*se4[4]), coef1[19]+(1.96*se4[5]),
            coef1[20]+(1.96*se4[6]))

lo1 <- c(coef1[1]-(1.96*se1[2]), coef1[2]-(1.96*se1[3]),
            coef1[3]-(1.96*se1[4]), coef1[4]-(1.96*se1[5]),
            coef1[5]-(1.96*se1[6]),
         coef1[6]-(1.96*se2[2]), coef1[7]-(1.96*se2[3]),
            coef1[8]-(1.96*se2[4]), coef1[9]-(1.96*se2[5]),
            coef1[10]-(1.96*se2[6]),
         coef1[11]-(1.96*se3[2]), coef1[12]-(1.96*se3[3]),
            coef1[13]-(1.96*se3[4]), coef1[14]-(1.96*se3[5]),
            coef1[15]-(1.96*se3[6]),
         coef1[16]-(1.96*se4[2]), coef1[17]-(1.96*se4[3]),
            coef1[18]-(1.96*se4[4]), coef1[19]-(1.96*se4[5]),
            coef1[20]-(1.96*se4[6]))

study <- c(rep('Study I', 10), rep('Study II', 10))
party <- rep(c('Democratic', 'Democratic', 'Democratic', 'Democratic', 'Democratic',
               'Republican', 'Republican', 'Republican', 'Republican',
               'Republican'), 2)
tr <- rep(c('eAnti-Vax', 'dDemocrat', 'cRepublican',
            'bAnti-Vax Democrat', 'aAnti-Vax Republican'), 4)

df_1 <- as.data.frame(cbind(coef1, hi1, lo1, party, tr, study))
df_1[, 1:3] <- lapply(df_1[, 1:3], as.numeric)
df_1[, 4:6] <- lapply(df_1[, 4:6], as.factor)
df_1$stupid <- str_c(df_1$party, ', ', df_1$study)


plot1 <- ggplot(df_1, aes(shape = party)) +
  theme_bw() +
  geom_vline(xintercept = 0, linetype = 'dashed') +
  geom_pointrange(aes(x = coef1, y = tr, xmin = lo1,
                         xmax = hi1, size = 3),
                     lwd = 1, position = position_dodge(width = 0.5), fill = 'WHITE') +
  xlim(-20, 50) +
  scale_shape_manual(name = 'Partisanship',
                    labels = c('Democrats', 'Republicans'),
                    values = c(15, 1)) +
  scale_y_discrete(name = 'Treatment Condition',
                   labels = c('Anti-Vax Republican', 'Anti-Vax Democrat',
                              'Republican', 'Democrat', 'Anti-Vax')) +
  scale_x_continuous("Estimated Effect on Blame Attributed to Victim") +
  facet_wrap(~study) +
  labs(title = 'Partisans Blame Deceased Anti-Vaxxers and Outpartisans for Own Death',
       caption = '\nNote: Estimated effects were calculated from two separate models (based on partisan identity). \nError bars represent 95/% confidence intervals. Full results table in Appendix E.') +
  theme(axis.text=element_text(size = 10)) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(plot.caption = element_text(hjust = 0)) +
  theme(text=element_text(size = 10, family="serif"))

plot1_sl <- ggplot(df_1, aes(shape = party)) +
  theme_bw() +
  geom_vline(xintercept = 0, linetype = 'dashed') +
  geom_pointrange(aes(x = coef1, y = tr, xmin = lo1,
                         xmax = hi1, size = 3),
                     lwd = 1, position = position_dodge(width = 0.5), fill = 'WHITE') +
  xlim(-20, 50) +
  scale_shape_manual(name = 'Partisanship',
                    labels = c('Democrats', 'Republicans'),
                    values = c(15, 1)) +
  scale_y_discrete(name = 'Treatment Condition',
                   labels = c('Anti-Vax Republican', 'Anti-Vax Democrat',
                              'Republican', 'Democrat', 'Anti-Vax')) +
  scale_x_continuous("Estimated Effect on Blame Attributed to Victim") +
  facet_wrap(~study) +
  labs(title = 'Partisans Blame Deceased Anti-Vaxxers and Outpartisans for Own Death') +
  theme(axis.text=element_text(size = 10)) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(plot.caption = element_text(hjust = 0)) +
  theme(text=element_text(size = 10, family="serif"))

# sympathy

coef2 <- c(m1_dem_4$coefficients[2:6], m1_gop_4$coefficients[2:6],
           m2_dem_4$coefficients[2:6], m2_gop_4$coefficients[2:6])
se1 <- sqrt(diag(vcov(m1_dem_4))); se2 <- sqrt(diag(vcov(m1_gop_4))); se3 <- sqrt(diag(vcov(m2_dem_4))); se4 <- sqrt(diag(vcov(m2_gop_4)))

hi2 <- c(coef2[1]+(1.96*se1[2]), coef2[2]+(1.96*se1[3]),
            coef2[3]+(1.96*se1[4]), coef2[4]+(1.96*se1[5]),
            coef2[5]+(1.96*se1[6]),
         coef2[6]+(1.96*se2[2]), coef2[7]+(1.96*se2[3]),
            coef2[8]+(1.96*se2[4]), coef2[9]+(1.96*se2[5]),
            coef2[10]+(1.96*se2[6]),
         coef2[11]+(1.96*se3[2]), coef2[12]+(1.96*se3[3]),
            coef2[13]+(1.96*se3[4]), coef2[14]+(1.96*se3[5]),
            coef2[15]+(1.96*se3[6]),
         coef2[16]+(1.96*se4[2]), coef2[17]+(1.96*se4[3]),
            coef2[18]+(1.96*se4[4]), coef2[19]+(1.96*se4[5]),
            coef2[20]+(1.96*se4[6]))

lo2 <- c(coef2[1]-(1.96*se1[2]), coef2[2]-(1.96*se1[3]),
            coef2[3]-(1.96*se1[4]), coef2[4]-(1.96*se1[5]),
            coef2[5]-(1.96*se1[6]),
         coef2[6]-(1.96*se2[2]), coef2[7]-(1.96*se2[3]),
            coef2[8]-(1.96*se2[4]), coef2[9]-(1.96*se2[5]),
            coef2[10]-(1.96*se2[6]),
         coef2[11]-(1.96*se3[2]), coef2[12]-(1.96*se3[3]),
            coef2[13]-(1.96*se3[4]), coef2[14]-(1.96*se3[5]),
            coef2[15]-(1.96*se3[6]),
         coef2[16]-(1.96*se4[2]), coef2[17]-(1.96*se4[3]),
            coef2[18]-(1.96*se4[4]), coef2[19]-(1.96*se4[5]),
            coef2[20]-(1.96*se4[6]))

df_2 <- as.data.frame(cbind(coef2, hi2, lo2, party, tr, study))
df_2[, 1:3] <- lapply(df_2[, 1:3], as.numeric)
df_2[, 4:6] <- lapply(df_2[, 4:6], as.factor)
df_2$stupid <- str_c(df_2$party, ', ', df_2$study)


plot2 <- ggplot(df_2, aes(shape = party)) +
  theme_bw() +
  geom_vline(xintercept = 0, linetype = 'dashed') +
  geom_pointrange(aes(x = coef2, y = tr, xmin = lo2,
                         xmax = hi2, size = 3),
                     lwd = 1, position = position_dodge(width = 0.5), fill = 'WHITE') +
  xlim(-20, 50) +
  scale_shape_manual(name = 'Partisanship',
                    labels = c('Democrats', 'Republicans'),
                    values = c(15, 1)) +
  scale_y_discrete(name = 'Treatment Condition',
                   labels = c('Anti-Vax Republican', 'Anti-Vax Democrat',
                              'Republican', 'Democrat', 'Anti-Vax')) +
  scale_x_continuous("Estimated Effect on Sympathy") +
  facet_wrap(~study) +
  labs(title = 'Partisanship Structures Sympathy for Covid Victims',
       caption = '\nNote: Estimated effects were calculated from two separate models (based on partisan identity). \nError bars represent 95/% confidence intervals. Full results table in Appendix E.') +
  theme(axis.text=element_text(size = 10)) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(plot.caption = element_text(hjust = 0)) +
  theme(text=element_text(size = 10, family="serif"))

plot2_sl <- ggplot(df_2, aes(shape = party)) +
  theme_bw() +
  geom_vline(xintercept = 0, linetype = 'dashed') +
  geom_pointrange(aes(x = coef2, y = tr, xmin = lo2,
                         xmax = hi2, size = 3),
                     lwd = 1, position = position_dodge(width = 0.5), fill = 'WHITE') +
  xlim(-20, 50) +
  scale_shape_manual(name = 'Partisanship',
                    labels = c('Democrats', 'Republicans'),
                    values = c(15, 1)) +
  scale_y_discrete(name = 'Treatment Condition',
                   labels = c('Anti-Vax Republican', 'Anti-Vax Democrat',
                              'Republican', 'Democrat', 'Anti-Vax')) +
  scale_x_continuous("Estimated Effect on Sympathy") +
  facet_wrap(~study) +
  labs(title = 'Partisanship Structures Sympathy for Covid Victims') +
  theme(axis.text=element_text(size = 10)) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(plot.caption = element_text(hjust = 0)) +
  theme(text=element_text(size = 10, family="serif"))

# Testing Group Empathy

## Blame

coef1 <- c(em_death1.1$coefficients[2:6], em_nodeath1.1$coefficients[2:6],
           em_death2.1$coefficients[2:6], em_nodeath2.1$coefficients[2:6])
se1 <- sqrt(diag(vcov(em_death1.1))); se2 <- sqrt(diag(vcov(em_nodeath1.1))); se3 <- sqrt(diag(vcov(em_death2.1))); se4 <- sqrt(diag(vcov(em_nodeath2.1)))

hi1 <- c(coef1[1]+(1.96*se1[2]), coef1[2]+(1.96*se1[3]),
            coef1[3]+(1.96*se1[4]), coef1[4]+(1.96*se1[5]),
            coef1[5]+(1.96*se1[6]),
         coef1[6]+(1.96*se2[2]), coef1[7]+(1.96*se2[3]),
            coef1[8]+(1.96*se2[4]), coef1[9]+(1.96*se2[5]),
            coef1[10]+(1.96*se2[6]),
         coef1[11]+(1.96*se3[2]), coef1[12]+(1.96*se3[3]),
            coef1[13]+(1.96*se3[4]), coef1[14]+(1.96*se3[5]),
            coef1[15]+(1.96*se3[6]),
         coef1[16]+(1.96*se4[2]), coef1[17]+(1.96*se4[3]),
            coef1[18]+(1.96*se4[4]), coef1[19]+(1.96*se4[5]),
            coef1[20]+(1.96*se4[6]))

lo1 <- c(coef1[1]-(1.96*se1[2]), coef1[2]-(1.96*se1[3]),
            coef1[3]-(1.96*se1[4]), coef1[4]-(1.96*se1[5]),
            coef1[5]-(1.96*se1[6]),
         coef1[6]-(1.96*se2[2]), coef1[7]-(1.96*se2[3]),
            coef1[8]-(1.96*se2[4]), coef1[9]-(1.96*se2[5]),
            coef1[10]-(1.96*se2[6]),
         coef1[11]-(1.96*se3[2]), coef1[12]-(1.96*se3[3]),
            coef1[13]-(1.96*se3[4]), coef1[14]-(1.96*se3[5]),
            coef1[15]-(1.96*se3[6]),
         coef1[16]-(1.96*se4[2]), coef1[17]-(1.96*se4[3]),
            coef1[18]-(1.96*se4[4]), coef1[19]-(1.96*se4[5]),
            coef1[20]-(1.96*se4[6]))

study <- c(rep('Study I', 10), rep('Study II', 10))
party <- rep(c('No', 'No', 'No', 'No', 'No',
               'Yes', 'Yes', 'Yes', 'Yes', 'Yes'), 2)
tr <- rep(c('eAnti-Vax', 'dDemocrat', 'cRepublican',
            'bAnti-Vax Democrat', 'aAnti-Vax Republican'), 4)

df_3 <- as.data.frame(cbind(coef1, hi1, lo1, party, tr, study))
df_3[, 1:3] <- lapply(df_3[, 1:3], as.numeric)
df_3[, 4:6] <- lapply(df_3[, 4:6], as.factor)
df_3$stupid <- str_c(df_3$party, ', ', df_3$study)


plot3 <- ggplot(df_3, aes(shape = party)) +
  theme_bw() +
  geom_vline(xintercept = 0, linetype = 'dashed') +
  geom_pointrange(aes(x = coef1, y = tr, xmin = lo1,
                         xmax = hi1, size = 3),
                     lwd = 1, position = position_dodge(width = 0.5), fill = 'WHITE') +
  xlim(-20, 50) +
  scale_shape_manual(name = 'Close Covid Death',
                    labels = c('Yes', 'No'),
                    values = c(15, 1)) +
  scale_y_discrete(name = 'Treatment Condition',
                   labels = c('Anti-Vax Republican', 'Anti-Vax Democrat',
                              'Republican', 'Democrat', 'Anti-Vax')) +
  scale_x_continuous("Estimated Effect on Blame Attributed to Victim") +
  facet_wrap(~study) +
  labs(title = 'Group Empathy and Blame Attribution',
       caption = '\nNote: Estimated effects were calculated from two separate models (based on partisan identity). \nError bars represent 95/% confidence intervals. Full results table in Appendix E.') +
  theme(axis.text=element_text(size = 10)) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(plot.caption = element_text(hjust = 0)) +
  theme(text=element_text(size = 10, family="serif"))

plot3_sl <- ggplot(df_3, aes(shape = party)) +
  theme_bw() +
  geom_vline(xintercept = 0, linetype = 'dashed') +
  geom_pointrange(aes(x = coef1, y = tr, xmin = lo1,
                         xmax = hi1, size = 3),
                     lwd = 1, position = position_dodge(width = 0.5), fill = 'WHITE') +
  xlim(-20, 50) +
  scale_shape_manual(name = 'Close Covid Death',
                    labels = c('Yes', 'No'),
                    values = c(15, 1)) +
  scale_y_discrete(name = 'Treatment Condition',
                   labels = c('Anti-Vax Republican', 'Anti-Vax Democrat',
                              'Republican', 'Democrat', 'Anti-Vax')) +
  scale_x_continuous("Estimated Effect on Blame Attributed to Victim") +
  facet_wrap(~study) +
  labs(title = 'Group Empathy and Blame Attribution') +
  theme(axis.text=element_text(size = 10)) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(plot.caption = element_text(hjust = 0)) +
  theme(text=element_text(size = 10, family="serif"))

## Sympathy

coef1 <- c(em_death1.2$coefficients[2:6], em_nodeath1.2$coefficients[2:6],
           em_death2.2$coefficients[2:6], em_nodeath2.2$coefficients[2:6])
se1 <- sqrt(diag(vcov(em_death1.2))); se2 <- sqrt(diag(vcov(em_nodeath1.2))); se3 <- sqrt(diag(vcov(em_death2.2))); se4 <- sqrt(diag(vcov(em_nodeath2.2)))

hi1 <- c(coef1[1]+(1.96*se1[2]), coef1[2]+(1.96*se1[3]),
            coef1[3]+(1.96*se1[4]), coef1[4]+(1.96*se1[5]),
            coef1[5]+(1.96*se1[6]),
         coef1[6]+(1.96*se2[2]), coef1[7]+(1.96*se2[3]),
            coef1[8]+(1.96*se2[4]), coef1[9]+(1.96*se2[5]),
            coef1[10]+(1.96*se2[6]),
         coef1[11]+(1.96*se3[2]), coef1[12]+(1.96*se3[3]),
            coef1[13]+(1.96*se3[4]), coef1[14]+(1.96*se3[5]),
            coef1[15]+(1.96*se3[6]),
         coef1[16]+(1.96*se4[2]), coef1[17]+(1.96*se4[3]),
            coef1[18]+(1.96*se4[4]), coef1[19]+(1.96*se4[5]),
            coef1[20]+(1.96*se4[6]))

lo1 <- c(coef1[1]-(1.96*se1[2]), coef1[2]-(1.96*se1[3]),
            coef1[3]-(1.96*se1[4]), coef1[4]-(1.96*se1[5]),
            coef1[5]-(1.96*se1[6]),
         coef1[6]-(1.96*se2[2]), coef1[7]-(1.96*se2[3]),
            coef1[8]-(1.96*se2[4]), coef1[9]-(1.96*se2[5]),
            coef1[10]-(1.96*se2[6]),
         coef1[11]-(1.96*se3[2]), coef1[12]-(1.96*se3[3]),
            coef1[13]-(1.96*se3[4]), coef1[14]-(1.96*se3[5]),
            coef1[15]-(1.96*se3[6]),
         coef1[16]-(1.96*se4[2]), coef1[17]-(1.96*se4[3]),
            coef1[18]-(1.96*se4[4]), coef1[19]-(1.96*se4[5]),
            coef1[20]-(1.96*se4[6]))

study <- c(rep('Study I', 10), rep('Study II', 10))
party <- rep(c('No', 'No', 'No', 'No', 'No',
               'Yes', 'Yes', 'Yes', 'Yes', 'Yes'), 2)
tr <- rep(c('eAnti-Vax', 'dDemocrat', 'cRepublican',
            'bAnti-Vax Democrat', 'aAnti-Vax Republican'), 4)

df_4 <- as.data.frame(cbind(coef1, hi1, lo1, party, tr, study))
df_4[, 1:3] <- lapply(df_4[, 1:3], as.numeric)
df_4[, 4:6] <- lapply(df_4[, 4:6], as.factor)
df_4$stupid <- str_c(df_4$party, ', ', df_4$study)


plot4 <- ggplot(df_4, aes(shape = party)) +
  theme_bw() +
  geom_vline(xintercept = 0, linetype = 'dashed') +
  geom_pointrange(aes(x = coef1, y = tr, xmin = lo1,
                         xmax = hi1, size = 3),
                     lwd = 1, position = position_dodge(width = 0.5), fill = 'WHITE') +
  xlim(-20, 50) +
  scale_shape_manual(name = 'Close Covid Death',
                    labels = c('Yes', 'No'),
                    values = c(15, 1)) +
  scale_y_discrete(name = 'Treatment Condition',
                   labels = c('Anti-Vax Republican', 'Anti-Vax Democrat',
                              'Republican', 'Democrat', 'Anti-Vax')) +
  scale_x_continuous("Estimated Effect on Sympathy for Victim") +
  facet_wrap(~study) +
  labs(title = 'Group Empathy and Sympathy',
       caption = '\nNote: Estimated effects were calculated from two separate models (based on partisan identity). \nError bars represent 95/% confidence intervals. Full results table in Appendix E.') +
  theme(axis.text=element_text(size = 10)) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(plot.caption = element_text(hjust = 0)) +
  theme(text=element_text(size = 10, family="serif"))

plot4_sl <- ggplot(df_4, aes(shape = party)) +
  theme_bw() +
  geom_vline(xintercept = 0, linetype = 'dashed') +
  geom_pointrange(aes(x = coef1, y = tr, xmin = lo1,
                         xmax = hi1, size = 3),
                     lwd = 1, position = position_dodge(width = 0.5), fill = 'WHITE') +
  xlim(-20, 50) +
  scale_shape_manual(name = 'Close Covid Death',
                    labels = c('Yes', 'No'),
                    values = c(15, 1)) +
  scale_y_discrete(name = 'Treatment Condition',
                   labels = c('Anti-Vax Republican', 'Anti-Vax Democrat',
                              'Republican', 'Democrat', 'Anti-Vax')) +
  scale_x_continuous("Estimated Effect on Sympathy for Victim") +
  facet_wrap(~study) +
  labs(title = 'Group Empathy and Sympathy') +
  theme(axis.text=element_text(size = 10)) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(plot.caption = element_text(hjust = 0)) +
  theme(text=element_text(size = 10, family="serif"))

plot1; plot2; plot3; plot4

# ggsave('plot1.png', plot1, 'png', '~/Dropbox/Wayde/Research/PostDiss_Trauma/CES21/Study1_Covid',
#     width = 190, height = 127, units = 'mm')
# ggsave('plot2.png', plot2, 'png', '~/Dropbox/Wayde/Research/PostDiss_Trauma/CES21/Study1_Covid',
#     width = 190, height = 127, units = 'mm')
# ggsave('plot3.png', plot3, 'png', '~/Dropbox/Wayde/Research/PostDiss_Trauma/CES21/Study1_Covid',
#     width = 190, height = 127, units = 'mm')
# ggsave('plot4.png', plot4, 'png', '~/Dropbox/Wayde/Research/PostDiss_Trauma/CES21/Study1_Covid',
#     width = 190, height = 127, units = 'mm')

# ggsave('plot1_sl.png', plot1_sl, 'png', '~/Dropbox/Wayde/Research/PostDiss_Trauma/CES21/Study1_Covid',
#     width = 190, height = 127, units = 'mm')
# ggsave('plot2_sl.png', plot2_sl, 'png', '~/Dropbox/Wayde/Research/PostDiss_Trauma/CES21/Study1_Covid',
#     width = 190, height = 127, units = 'mm')
# ggsave('plot3_sl.png', plot3_sl, 'png', '~/Dropbox/Wayde/Research/PostDiss_Trauma/CES21/Study1_Covid',
#     width = 190, height = 127, units = 'mm')
# ggsave('plot4_sl.png', plot4_sl, 'png', '~/Dropbox/Wayde/Research/PostDiss_Trauma/CES21/Study1_Covid',
#     width = 190, height = 127, units = 'mm')

```

## Alternative Modeling Approaches

```{r}

df$tr_vax <- ifelse((df$tr1 == 2 | df$tr1 > 4 ), 1, 0)
df$tr_out <- ifelse(df$gop == 1 & (df$tr1 == 3 | df$tr1 == 5), 1,
             ifelse(df$gop == 0 & (df$tr1 == 4 | df$tr1 == 6), 1, 0))
df2$tr_vax <- ifelse((df2$trgrp == 2 | df2$trgrp > 4 ), 1, 0)
df2$tr_out <- ifelse(df2$gop == 1 & (df2$trgrp == 3 | df2$trgrp == 5), 1,
             ifelse(df2$gop == 0 & (df2$trgrp == 4 | df2$trgrp == 6), 1, 0))

m_add_blm <- lm(study1_dv_1 ~ tr_vax*tr_out, data = df) 
summary(m_add_blm)
m_add_sym <- lm(study1_dv2_1 ~ tr_vax*tr_out, data = df) 
summary(m_add_sym)
m_add_blm2 <- lm(study1_dv_1 ~ tr_vax*tr_out, weights = teamweight, data = df2) 
summary(m_add_blm2)
m_add_sym2 <- lm(study1_dv2_1 ~ tr_vax*tr_out, weights = teamweight, data = df2) 
summary(m_add_sym2)

m_add_blm_r <- lm(study1_dv_1 ~ tr_vax*tr_out, data = subset(df, gop == 1)) 
summary(m_add_blm_r)
m_add_sym_r <- lm(study1_dv2_1 ~ tr_vax*tr_out, data = subset(df, gop == 1)) 
summary(m_add_sym_r)
m_add_blm_r2 <- lm(study1_dv_1 ~ tr_vax*tr_out, weights = teamweight, 
                   data = subset(df2, gop == 1)) 
summary(m_add_blm_r2)
m_add_sym_r2 <- lm(study1_dv2_1 ~ tr_vax*tr_out, weights = teamweight,
                   data = subset(df2, gop == 1)) 
summary(m_add_sym_r2)

m_add_blm_d <- lm(study1_dv_1 ~ tr_vax*tr_out, data = subset(df, gop == 0)) 
summary(m_add_blm_d)
m_add_sym_d <- lm(study1_dv2_1 ~ tr_vax*tr_out, data = subset(df, gop == 0)) 
summary(m_add_sym_d)
m_add_blm_d2 <- lm(study1_dv_1 ~ tr_vax*tr_out, weights = teamweight,
                   data = subset(df2, gop == 0)) 
summary(m_add_blm_d2)
m_add_sym_d2 <- lm(study1_dv2_1 ~ tr_vax*tr_out, weights = teamweight,
                   data = subset(df2, gop == 0)) 
summary(m_add_sym_d2)

modelsummary(models = list('Blame'  = m_add_blm,
                           'Sympathy' = m_add_sym,
                           'Blame'  = m_add_blm2,
                           'Sympathy' = m_add_sym2),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

modelsummary(models = list('Blame'  = m_add_blm_r,
                           'Sympathy' = m_add_sym_r,
                           'Blame'  = m_add_blm_r2,
                           'Sympathy' = m_add_sym_r2),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

modelsummary(models = list('Blame'  = m_add_blm_d,
                           'Sympathy' = m_add_sym_d,
                           'Blame'  = m_add_blm_d2,
                           'Sympathy' = m_add_sym_d2),
             output = 'latex',
             stars = c('*' = .05),
             gof_omit = 'AIC|BIC|F|RMSE|Log.Lik.',
             escape = FALSE)

```

